package com.feonix.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 密码强度判断
 * @author feonix
 *
 */
public class CheckPwdStrong {

	private static final Pattern pattern1 = Pattern.compile("[a-zA-Z]+");

	private static final Pattern pattern2 = Pattern.compile("[0-9]+");

	private static final Pattern pattern3 = Pattern.compile("\\W+|_+");
	public static final int PWDSLEVEL_L = 0;
	public static final int PWDSLEVEL_M = 1;
	public static final int PWDSLEVEL_S = 2;

	public static Integer check(String password) {
		int i = 0;
		Matcher matcher = null;
		if ((password == null) || (password.trim().length() < 6)) {
			i = 0;
		} else {
			int j = 0;
			matcher = pattern1.matcher(password);
			if (matcher.find()) {
				++j;
			}

			matcher = pattern2.matcher(password);
			if (matcher.find()) {
				++j;
			}
			matcher = pattern3.matcher(password);
			if (matcher.find()) {
				++j;
			}
			switch (j) {
			case 0:
				i = 0;
				break;
			case 1:
				i = 0;
				break;
			case 2:
				i = 1;
				break;
			case 3:
				i = 2;
				break;
			case 4:
				i = 2;
			}
		}

		return Integer.valueOf(i);
	}

}
